NSOpenGLContext *shared_gl_context = nil;
NSOpenGLContext *gl_context;
NSOpenGLPixelFormat *pixelFormat;
+ CGLContextObj cgl_context;
GdkGLContext *shared;
GdkGLContext *shared_data;
NSOpenGLContext *existing;
GLint sync_to_framerate = 1;
GLint validate = 0;
+ GLint swapRect[4];
int major, minor;
g_assert (GDK_IS_MACOS_GL_CONTEXT (self));
return FALSE;
}
- [gl_context setValues:&sync_to_framerate forParameter:NSOpenGLCPSwapInterval];
- [gl_context setValues:&validate forParameter:NSOpenGLContextParameterStateValidation];
+ cgl_context = [gl_context CGLContextObj];
+
+ swapRect[0] = 0;
+ swapRect[1] = 0;
+ swapRect[2] = surface->width;
+ swapRect[3] = surface->height;
+
+ CGLSetParameter (cgl_context, kCGLCPSwapRectangle, swapRect);
+ CGLSetParameter (cgl_context, kCGLCPSwapInterval, &sync_to_framerate);
+
+ CGLEnable (cgl_context, kCGLCESwapRectangle);
+ if (validate)
+ CGLEnable (cgl_context, kCGLCEStateValidation);
self->dummy_window = [[NSWindow alloc] initWithContentRect:NSZeroRect
styleMask:0
cairo_region_t *painted)
{
GdkMacosGLContext *self = (GdkMacosGLContext *)context;
+ GdkSurface *surface;
g_assert (GDK_IS_MACOS_GL_CONTEXT (self));
+ surface = gdk_draw_context_get_surface (context);
+
/* If begin frame is called, that means we are trying to draw to
* the NSWindow using our view. That might be a GdkMacosCairoView
* but we need it to be a GL view. Also, only in this case do we
if (!self->is_attached &&
gdk_gl_context_get_shared_context (GDK_GL_CONTEXT (context)))
{
+ CGLContextObj glctx = [self->gl_context CGLContextObj];
+ GLint swapRect[4];
+
ensure_gl_view (self);
g_clear_pointer (&self->damage, cairo_region_destroy);
self->damage = cairo_region_copy (painted);
cairo_region_get_extents (painted, &self->flush_rect);
+
+ /* Coordinates are in display coordinates, where as flush_rect is
+ * in GDK coordinates. Must flip Y to match display coordinates where
+ * 0,0 is the bottom-left corner.
+ */
+ swapRect[0] = self->flush_rect.x; /* left */
+ swapRect[1] = surface->height - self->flush_rect.y; /* bottom */
+ swapRect[2] = self->flush_rect.width; /* width */
+ swapRect[3] = self->flush_rect.height; /* height */
+
+ CGLSetParameter (glctx, kCGLCPSwapRectangle, swapRect);
}
if (self->needs_resize)
{
- GdkSurface *surface = gdk_draw_context_get_surface (context);
+ CGLContextObj cgl_context = [self->gl_context CGLContextObj];
GLint opaque;
self->needs_resize = FALSE;
opaque = GDK_MACOS_TOPLEVEL_SURFACE (surface)->decorated;
else
opaque = FALSE;
- [self->gl_context setValues:&opaque forParameter:NSOpenGLCPSurfaceOpacity];
+
+ CGLSetParameter (cgl_context, kCGLCPSurfaceOpacity, &opaque);
[self->gl_context update];
}
if (!self->is_attached)
{
- GdkMacosSurface *surface = GDK_MACOS_SURFACE (gdk_draw_context_get_surface (context));
- NSView *nsview = _gdk_macos_surface_get_view (surface);
+ NSView *nsview = _gdk_macos_surface_get_view (GDK_MACOS_SURFACE (surface));
g_assert (self->gl_context != NULL);
g_assert (GDK_IS_MACOS_GL_VIEW (nsview));
GDK_DRAW_CONTEXT_CLASS (gdk_macos_gl_context_parent_class)->end_frame (context, painted);
- /* We want to limit how much gets moved to the front buffer so here
- * we adjust the clip rectangle before flushBuffer is called.
- */
- G_STATIC_ASSERT (sizeof (GLint) == sizeof (int));
- [self->gl_context
- setValues:(GLint *)&self->flush_rect
- forParameter:NSOpenGLCPSwapRectangle];
-
[self->gl_context flushBuffer];
}